package com.villaday.idf.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.model.Cities_villagesEntity;
import com.villaday.idf.model.RefreshtokenEntity;
import com.villaday.idf.model.TopicEntity;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.SharedPreferencesUtil;

/**
 * 首页动态列表
 */

public class BournAdapter extends AbsRecyclerViewAdapter<Cities_villagesEntity.BodyEntity.ListEntity> {
    private OnAdapterCallbackListener onAdapterCallbackListener;
    private View.OnClickListener onClickListener;
    private  String roleType;


    public BournAdapter(Context context, OnAdapterCallbackListener onAdapterCallbackListener, View.OnClickListener onClickListener) {
        super(context, R.layout.item_find_house_bieshu2, R.layout.item_page_loading,
                R.layout.item_page_bottom,R.layout.item_find_house_bieshu_0);
        this.onAdapterCallbackListener = onAdapterCallbackListener;
        this.onClickListener = onClickListener;
        RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(context);
        roleType = roleInfo.getMember().getType();

    }
    public void setRoleType(){
        RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(context);
        roleType = roleInfo.getMember().getType();
    }

    @Override
    public int getItemType(Cities_villagesEntity.BodyEntity.ListEntity d) {
        return d.getType();
    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, Cities_villagesEntity.BodyEntity.ListEntity d, int position) {


        switch (d.getType()) {
            case 0:
                case 3:
                holder.bindSimpleDraweeView(R.id.sdv, d.getImageURL()+"")
                        .bindTextViewWithHtml(R.id.tv_priceFuHao,"&yen;")

                        .bindTextView(R.id.tv_title, d.getName())
                        .bindTextView(R.id.tv_des, "介绍："+d.getDescription())
                        .setViewVisible(R.id.tv_tuiguang, "0".equals(roleType) ? View.INVISIBLE : View.VISIBLE)

                        .setViewVisible(R.id.tv_hot, d.isHotVillage() ? View.GONE : View.GONE)
                        .bindTextView(R.id.detail, d.getAddress())
                        .setClickListenerAndTag(R.id.tv_tuiguang,onClickListener,position)
                        .bindTextViewWithHtml(R.id.tv_price,   d.getCurrentPriceValue())
                        .setViewVisible(R.id.tv_tuiguang, "0".equals(roleType) ? View.INVISIBLE : View.VISIBLE);


                PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_priceFuHao),true);
                PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_price),true);
                PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_qi),false);



                break;
            case 1:
                onAdapterCallbackListener.onCallback();
                break;
        }


    }
}
